<template>
  <div class="bj-28" v-if="!getIsPhone">
    <select-number-public
      :options="options"
      :winningInfo="winningInfo"
      :winningNumbers="winningNumbers"
      :currentLottery="getLotteryType.lotteryName"
      @mutate="handleMutate"
    >
      <template v-slot:winninginfo>
        <winning-numbers :winningNumbers="winningNumbers">
          <winning-info-28 :winningNumbers="winningNumbers"></winning-info-28>
        </winning-numbers>
      </template>
      <transition name="fade" mode="out-in">
        <component :is="getCurrentComponent"></component>
      </transition>
    </select-number-public>
  </div>
  <div class="bj-28-phone" v-else>
    <div class="fixed-top">
      <winning-numbers :winningNumbers="winningNumbers">
        <div class="numbers">
          <span 
            class="border-right"
            v-for="(number, index) in winningNumbers.previous.numbers.split(',')" 
            :key="index"
            :class="'dd-color-' + number"
          >{{number}}</span>
          <span class="eq border-right">
            =
          </span>
          <span class="sum border-right" :class="'dd-color-' + sum(winningNumbers.previous.numbers.split(','))">
            {{sum(winningNumbers.previous.numbers.split(','))}}
          </span>
        </div>
      </winning-numbers>
      <sub-dropdown-phone></sub-dropdown-phone>
    </div>
    <transition name="fade" mode="out-in">
      <component :is="getCurrentComponent"></component>
    </transition>
    <side-slider-phone :options="options" @click="handleMutate"></side-slider-phone>
  </div>
</template>

<script>
import SelectNumberPublic from '@/components/select-number-public/select-number-public'
import WinningNumbers from '@/components/winning-numbers/winning-numbers'
import WinningInfo28 from '@/components/winning-info/winning-info-28'
import tema28 from '@/components/lottery-type/bj28/tema/tema'
import tema28baosan from '@/components/lottery-type/bj28/temabaosan/temabaosan'
import tema28hunhe from '@/components/lottery-type/bj28/hunhe/hunhe'
import SideSliderPhone from '@/components/base/phone/side-slider-phone/side-slider-phone'
import SubDropdownPhone from '@/components/base/phone/sub-dropdown-phone/sub-dropdown-phone'

import { sumArr } from '@/assets/js/util.js'
import { mapGetters, mapMutations } from 'vuex'

export default {
  components: {
    SelectNumberPublic,
    WinningNumbers,
    WinningInfo28,
    tema28,
    tema28baosan,
    tema28hunhe,
    SideSliderPhone,
    SubDropdownPhone,
  },
  data() {
    return {
      // 开奖信息
      winningNumbers: {
        id: 'bj28',
        lotteryName: '北京28',
        dateNo: '819048',
        previous: {
          dateNo: '819049',
          numbers: '2,3,5',
          context: '13，大，小',
        },
        closeTime: new Date().getTime() + 1000000,
        drawTime: new Date().getTime() + 10000000
      },
      // 上期中奖信息
      winningInfo: [
        { 
          id: 1,
          series: 819049,
          numbers: '3,2,5'
        },
        {
          id: 2,
          series: 819049,
          numbers: '3,2,5'
        },
        {
          id: 3,
          series: 819049,
          numbers: '3,2,5'
        },
        {
          id: 4,
          series: 819049,
          numbers: '3,2,5'
        },
        {
          id: 5,
          series: 819049,
          numbers: '3,2,5'
        },
        {
          id: 6,
          series: 819049,
          numbers: '3,2,5'
        },
        {
          id: 7,
          series: 819049,
          numbers:'3,2,5'
        },
        {
          id: 8,
          series: 819049,
          numbers: '3,2,5'
        },
        {
          id: 9,
          series: 819049,
          numbers: '3,2,5'
        }
      ],
      // tab选项
      options: [
        {
          id: 'tema',
          context: '特码',
          currentComponent: 'tema28',
          currentSubTab: '特码',
          currentSubId: 'tema28',
          sub: [
            {
              cate: '玩法',
              tabnames: [
                {
                  id: 'tema28',
                  context: '特码',
                  components: 'tema28'
                }
              ]
            }
          ]
        },
        {
          id: 'tm_sb',
          context: '特码包三',
          currentSubId: 'tm_sb',
          currentComponent: 'tema28baosan',
          currentSubTab: '特码包三',
          sub: [
            {
              cate: '玩法',
              tabnames: [
                {
                  id: 'tm_sb',
                  context: '特码包三',
                  components: 'tema28baosan'
                }
              ]
            }
          ]
        },
        {
          id: 'h_h',
          context: '混合',
          currentSubId: 'h_h',
          currentComponent: 'tema28hunhe',
          currentSubTab: '混合',
          sub: [
            {
              cate: '玩法',
              tabnames: [
                {
                  id: 'h_h',
                  context: '混合',
                  components: 'tema28hunhe'
                },
              ]
            }
          ]
        },
      ],
    }
  },
  created() {
    this.setLotteryType({lotteryName: this.winningNumbers.lotteryName, id: this.winningNumbers.id})
    this.setCurrentLotteryDateNo(this.winningNumbers.dateNo)
    this.setCurrentComponent(this.options[0].currentComponent)
    this.setCurrentMainTab({mainTabName: this.options[0].context, id: this.options[0].id })
    this.setCurrentTab({subTabName: this.options[0].currentSubTab, id: this.options[0].currentSubId})
  },
  methods: {
    handleMutate(options) {
      this.options = options
    },
    ...mapMutations('lottery', {
      setLotteryType: 'SET_LOTTERY_TYPE',
      setCurrentComponent: 'SET_CURRENT_COMPONENT',
      setCurrentMainTab: 'SET_CURRENT_MAIN_TAB',
      setCurrentTab: 'SET_CURRENT_TAB',
      setCurrentLotteryDateNo: 'SET_CURRENT_LOTTERY_DATE_NO'
    }),
    sum(arr) {
      return sumArr(arr)
    }
  },
  computed: {
    ...mapGetters('lottery', [
      'getCurrentComponent',
      'getIsPhone',
      'getLotteryType'
    ])
  }
}
</script>

<style lang="stylus" scoped>
  &.fade-enter, &.fade-leave-to 
    opacity 0
  &.fade-leave, &.fade-enter-to 
    opacity 1
  &.fade-enter-active, &.fade-leave-active 
    transition all 0.2s 
  @media screen and (max-width 750px) 
    .bj-28-phone 
      width 100%
      box-sizing border-box
      padding-top 148px
      padding-bottom 50px
      .fixed-top 
        position fixed 
        top 48px 
        left 0 
        right 0 
        z-index 9
        background #fff
        .numbers 
          font-size 0
          span  
            display inline-block
            width 23px
            height 10px
            line-height 10px
            margin-right 0
            border-radius 0
            color $color-theme-red 
            border-right 1px solid $color-divide-line
            text-align center
            font-size 16px 
            font-family $sub-font-family
            font-weight 700
            &.sum 
              min-width 30px
</style>